package com.homedo.odin.solution.enumcode.user;

import java.util.Arrays;
import lombok.Getter;

@Getter
public enum DealTypeEnum {
    WAIT_TO_DEAL(0, "待处理"),
    DEAL_ING(10, "处理中"),
    ALREAD_DEAL(20, "已处理"),
    ALREAD_DEL(30, "已删除");

    private Integer dbValue;
    private String displayValue;

    DealTypeEnum(Integer key, String value) {
        this.displayValue = value;
        this.dbValue = key;
    }

    /**
     * 判断是否存在枚举dbValue
     */
    public static boolean dbValueExist(Integer dbValue) {
        return Arrays.stream(DealTypeEnum.values()).anyMatch(obj -> obj.getDbValue().equals(dbValue));
    }

    /**
     * 判断是否存在枚举displayValue
     */
    public static boolean displayValueExist(String displayValue) {
        return Arrays.stream(DealTypeEnum.values()).anyMatch(obj -> obj.getDisplayValue().equals(displayValue));
    }


    /**
     * 匹配获取对应的DisplayValue
     */
    public static String getExistDisplayValue(Integer dbValue) {
        return Arrays.stream(DealTypeEnum.values()).filter(obj -> obj.getDbValue().equals(dbValue))
                .map(obj -> obj.getDisplayValue()).findFirst().orElse(null);
    }
}
